#ifndef MAINWINDOW_H
#define MAINWINDOW_H


#include <QMainWindow>
#include <QtCharts/QChartGlobal>
#include <QtCharts/QChart>


#include <QString>
#include <QLineSeries>
#include <QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QLabel>
#include <QMouseEvent>
#include <QPainter>
#include <QStyleOption>
#include <QValueAxis>
#include <QMessageBox>
#include "qtimer.h"
#include <dbase.h>
QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    int count = 0;
    QString date[6];
    QString temperature[6];
    QString weather_type[6];
    QLabel *lab_temp_range[6];
    QLabel *lab_date[6];
    QLabel *lab_weather_type_pic[6];
    QString data_mqtt[6];//存储mqtt
    double value[4],thre[6];
    QJsonValue time;
/*********************************重写鼠标函数***********************************/
    virtual void mousePressEvent(QMouseEvent *event) override;
    virtual void mouseMoveEvent(QMouseEvent *event) override;
    virtual void mouseReleaseEvent(QMouseEvent *event) override;
/*********************************UI显示相关函数*********************************/
    void chartInit();
    void windowInit();
    QString TEXT_COLOR(QString color,QString str);//使用html
/********************************oneNet相关函数********************************/
    void post_Mqtt(int type);
    void json_Mqtt(QNetworkReply *reply);
/*********************************天气相关函数*********************************/
    void get_Ip(void);
    void json_Ip(QNetworkReply *reply);
    void get_City(QString ip);
    //json解析
    void json_City(QNetworkReply *reply);
    void get_Weather(QString city);
    void json_Weather(QNetworkReply *reply);
    void get_Weathers(QString city);
    void json_Weathers(QNetworkReply *reply);
    void weather_data_Update();
signals:
    void ss_run();
protected:

private slots:
    void windowcolse();
    void windowmin();
    void windowmax();
    void userCt();
    void dataCt();
    void weatherCt();
    void on_LocateBt_Clicked();
    void loginCt();
    void registerCt();
    void alterCt();
    void nodifyCt();
    void deleteCt();
    void exitCt();
    void switchLedCt();
    void switchFanCt();
    void switchPumpCt();
    void switchLeftCt();
    void switchRightCt();
    void switchAutoCt();

    void sliderMoved2();


    void sliderReleased2();

    void mqtt_data_Update();
    void get_Mqtt();
private:
    Ui::MainWindow *ui;
    QLineSeries *serieTemp = new QLineSeries();//温度
    QLineSeries *serieHumi = new QLineSeries();//湿度
    QLineSeries *serieLight = new QLineSeries();//光照强度
    QLineSeries *serieOhumi = new QLineSeries();//土壤湿度
    QLineSeries *serieCo2 = new QLineSeries();//二氧化碳
    QChart* chart1 = new QChart();
    QChart* chart2 = new QChart();
    QChart* chart3 = new QChart();
    QChart* chart4 = new QChart();
    QNetworkAccessManager requst_ip;
    QNetworkAccessManager requst_city;
    QNetworkAccessManager requst_weather;
    QNetworkAccessManager requst_weathers;
    QNetworkAccessManager requst_mqtt;
    QMap<QString,QString> map1 = {{"暴雪","snwoy4"},{"暴雨","rain4"},{"冰雹","hail"},{"大雪","snowy3"},{"大雨","rain4"},
                                   {"多云","cloudy1"},{"阵雨","shower"},{"雷阵雨","thunderrain"},{"霾","haze"},
                                   {"晴","sun"},{"雾","vapor"},{"小雪","snwoy1"},{"小雨","rain1"},{"阴","cloudy2"},
                                   {"雨夹雪","snowyrain"},{"中雪","snwoy2"},{"中雨","rain2"}};
    int controlFlag = 0;
    dbase *d = new dbase();
    struct_user* db_list = new struct_user[20];
    const int AXIS_MAX_X = 60;
    struct_user *u = new struct_user();
    QTimer *timer1 = new QTimer();
    QTimer *timer2 = new QTimer();
    QValueAxis *axisX1,*axisY1,*axisX2,*axisY2,*axisX3,*axisY3,*axisX4,*axisY4;
    bool status = false,sw1 = false,sw2 = false,sw3 = false;
    QPoint diff_pos;  // 鼠标和窗口的相对位移

};
#endif // MAINWINDOW_H
